package com.thenmoret.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.thenmoret.mapper.ArticleMapper;
import com.thenmoret.pojo.Article;
import com.thenmoret.service.ArticleService;

@Service
public class ArticleServiceImpl implements ArticleService {

	@Autowired
	private ArticleMapper articleMapper;

	@Override
	public Integer addArticle(Article article) {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String datetime = sdf.format(new Date());
		article.setArticleTime(datetime);
		article.setArticleAuthor("thenmore");
		return articleMapper.insert(article);

	}

	@Override
	public Integer deleteArticle(Integer id) {
		return articleMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Article findArticleById(Integer id) {

		return articleMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Article> findArticleList() {
		List<Article> list = articleMapper.selectByList();
		return list;
	}

	@Override
	public Integer updateArticle(Article article) {
		return articleMapper.updateByPrimaryKeySelective(article);
	}

	@Override
	public List<Article> findByPage(Integer start, Integer end) {
		return articleMapper.selectBypage(start, end);
	}

}
